﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CSharpLexer {
	public class Token {
		public enum TokenType {
			// C# spec §2.4
			IDENTIFIER,
			KEYWORD,
			INTEGRAL_LITERAL,
			REAL_LITERAL,
			CHARACTER_LITERAL,
			STRING_LITERAL,
			OPERATOR_OR_PUNCTUATOR,
			// Not part of C#'s specification, but useful for an IDE:
			COMMENT,
			EOF,
			ERROR,
		}
		public readonly string Lexeme;
		public readonly int Pos;
		public readonly int Length;
		public readonly TokenType Type;

		public Token(TokenType type, string lexeme, int pos, int length) {
			Type = type;
			Lexeme = lexeme;
			Pos = pos;
			Length = length;
		}

		public override string ToString() {
			return String.Format("{0}[{1},{2})({3})", Type.ToString(), Pos, Pos + Length, Lexeme);
		}

		public override bool Equals(object obj) {
			return obj is Token &&
				Lexeme == (obj as Token).Lexeme &&
				Pos == (obj as Token).Pos &&
				Length == (obj as Token).Length &&
				Type == (obj as Token).Type;
		}

		public override int GetHashCode() {
			return
				Lexeme.GetHashCode() ^
				Pos.GetHashCode() ^
				Length.GetHashCode() ^
				Type.GetHashCode();
		}
	}
}
